#include "GUI_event.h"
#include "GUI_draw.h"
#include "editbox.h"
#include "button.h"
#include "form.h"

static int create_lt(point_s *parr)
{
	int i;
	point_s tmp = {20,0};

	for(i = 0;; i ++)
	{
		tmp.x = 20;
		tmp.y += 20;
		CPY_POINT_S(parr[i],tmp);
		if(tmp.y >= Y_LENTH - 20)
			break;
	}
	tmp.x = 0;
	for(;; i ++)
	{
		tmp.y = Y_LENTH - 20;
		tmp.x += 20;
		CPY_POINT_S(parr[i],tmp);
		if(tmp.x >= X_LENTH - 20)
			break;
	}
	return i;
}

static int create_rb(point_s *parr)
{
	int i;
	point_s tmp = {X_LENTH,Y_LENTH};

	for(i = 0;; i ++)
	{
		tmp.x = X_LENTH - 20;
		tmp.y -= 20;
		CPY_POINT_S(parr[i],tmp);
		if(tmp.y >= Y_LENTH - 20)
			break;
	}
	tmp.x = 0;
	for(;; i ++)
	{
		tmp.y = Y_LENTH - 20;
		tmp.x += 20;
		CPY_POINT_S(parr[i],tmp);
		if(tmp.x >= X_LENTH - 20)
			break;
	}
	return i;
}

void test_draw(void)
{
	color_s color1;
	int hpoisize = 50,i;
	point_s lt,rb,t1,t2;
	color1.value = 0xffff;
	
	flushWndImg(color1);
	color1.value = 0xff0000;

	SET_POINT_S(t1,20,20);
	SET_POINT_S(t2,20,20);

	for(i = 0;i < 30;i ++)
	{
		t1.y += 20;
		t2.x += 20;
		CPY_POINT_S(lt,t1);
		CPY_POINT_S(rb,t2);

		if(lt.y > Y_LENTH - 20)
		{
			lt.y = Y_LENTH - 20;
			lt.x = 40 + (i + 2)*20 - Y_LENTH;
		}
		else if(rb.x > X_LENTH - 20)
		{
			rb.x = X_LENTH - 20;
			rb.y = 40 + (i + 2) * 20 - X_LENTH;
		}
		if((rb.y > Y_LENTH - 20) && (lt.x > X_LENTH - 20))
		{
			break;
		}
		//if(lt.y <= 0 || lt.x <= 0 || rb.y <= 0 || rb.x <= 0 )
		//	lt.y = 0;
		drawWndimgLine(&lt,&rb, color1);
	}


	SET_POINT_S(t1,20,Y_LENTH - 20);
	SET_POINT_S(t2,20,Y_LENTH - 20);

	for(i = 0;i < 30;i ++)
	{
		t1.y -= 20;
		t2.x += 20;
		CPY_POINT_S(lt,t1);
		CPY_POINT_S(rb,t2);

		if(lt.y < 20)
		{
			lt.x = (40 - lt.y);
			lt.y = 20;
		}

		if(rb.x > X_LENTH - 20)
		{
			rb.y = X_LENTH - rb.x;
			rb.x = X_LENTH - 20;
		}
		if((rb.y < 20) && (lt.x > X_LENTH - 20))
		{
			break;
		}		
		drawWndimgLine(&lt,&rb, color1);
	}
	SET_POINT_S(lt,20,20);
	SET_POINT_S(rb,X_LENTH - 20,Y_LENTH - 20);
	drawRectangle(&lt,&rb, color1);
}

void testTable(void)
{
	point_s lt,rb,size;
	color_s color1;
	lt.x = 20;
	lt.y = 20;
	rb.x = X_LENTH - 20;
	rb.y = Y_LENTH - 20;
	size.x = 20;
	size.y = 20;
	color1.value = COLOR_DEEPSKYBLUE;
	flushWndImg(color1);
	color1.value = 0xff0000;
	drawTable(&lt,&rb,&size, color1);

}

void test_button(void)
{
	wnd_base *base;
	button *bt;
	color_s color1;
	color1.value = COLOR_DEEPSKYBLUE;
	flushWndImg(color1);
	bt = new_obj(button);
	base = &bt->base;
	base->setPosition(base,20,20);
	base->setSize(base,80,40);
	base->setFocus(base,1);
	bt->base.draw((wnd_base *)bt);
	delete_obj(bt);
}

void test_editbox(void)
{
	wnd_base *base;
	editbox *edit;
	color_s color1;

	color1.value = COLOR_DEEPSKYBLUE;
	flushWndImg(color1);

	edit = new_obj(editbox);
	base = &edit->base;
	base->setPosition(base,60,20);
	base->setSize(base,80,40);
	base->setFocus(base,1);
	edit->base.draw((wnd_base *)edit);
	delete_obj(edit);
}

void test_form(void)
{
	wnd_base *base;
	form_c *form = new_obj(form_c);
	
	base = &form->base;
	form->base.draw((wnd_base *)form);
	delete_obj(form);
}

